home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MISC / SHELL.ARC / Shell / Sources / c / BlockRect < prev    next >
Text File  |  1994-06-25  |  2KB  |  107 lines

  1. #include "DeskLib:WimpSWIs.h"
  2. #include "DeskLib:GFX.h"
  3.  
  4. #include "Shell.BlockRct.h"
  5. #include "Shell.Extra.h"
  6. #include "Shell.SafeAlloc.h"
  7.  
  8.  
  9.  
  10. typedef struct    {
  11.     Shell_GeneralBlockRectFn    fn;
  12.     void                *reference;
  13.     int                width, height;
  14.     int                maxx, maxy;
  15.     }
  16.     Shell_GeneralBlockRectInfo;
  17.  
  18.  
  19.  
  20.  
  21.  
  22. static void Shell_GeneralBlockRectRedrawer(
  23.     Shell_convertpoint    convert,
  24.     wimp_point        rectsize,
  25.     void            *reference,
  26.     const wimp_rect        *redrawrect
  27.     )
  28. {
  29.     wimp_rect            rect = *redrawrect;
  30.     Shell_GeneralBlockRectInfo    *info;
  31.  
  32. info = (Shell_GeneralBlockRectInfo *) reference;
  33.  
  34. Shell_ConvertToSubRect2( &rect, rectsize);
  35. rect.min.x /= info->width;
  36. rect.max.x /= info->width;
  37. rect.min.y /= info->height;
  38. rect.max.y /= info->height;
  39.  
  40.     {    int i, j;
  41.  
  42.     for ( i=rect.min.x; i<=rect.max.x; i++)    {
  43.         int x = i*info->width;
  44.         for ( j=rect.min.y; j<=rect.max.y; j++)    {
  45.             int    col = info->fn( i, j, info->maxx, info->maxy, info->reference);
  46.             Wimp_SetColour( col);
  47.             Shell_RectangleFill3(
  48.                 x, j*info->height,
  49.                 info->width    - Shell_PIXELXSIZE,
  50.                 info->height    - Shell_PIXELYSIZE,
  51.                 convert
  52.                 );
  53.             }
  54.         }
  55.     }
  56.  
  57. return;
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. Shell_rectblock *Shell_AddGeneralBlockRect(
  68.     Shell_windblock            *wind,
  69.     int                x,
  70.     int                y,
  71.     int                maxx,
  72.     int                maxy,
  73.     int                width,
  74.     int                height,
  75.     Shell_GeneralBlockRectFn    fn,
  76.     const void            *reference
  77.     )
  78. {
  79.     wimp_rect            rect;
  80.     Shell_GeneralBlockRectInfo    *info;
  81.     Shell_rectblock *r;
  82.  
  83. info = Shell_SafeMalloc( sizeof( Shell_GeneralBlockRectInfo));
  84.  
  85. info->fn = fn;
  86. info->width = width;
  87. info->height = height;
  88. info->maxx = maxx;
  89. info->maxy = maxy;
  90. info->reference = (void *) reference;
  91. rect.max.x = x+maxx*width;
  92. rect.max.y = y+maxy*height;
  93.  
  94. rect.min.x = x;
  95. rect.min.y = y;
  96.  
  97. r = Shell_AddRectangle( wind, &rect, Shell_GeneralBlockRectRedrawer, (void *) info);
  98.  
  99. /* Could call Shell_MakeRectIcon here to give the blockrect a border.    */
  100. /* However, I sometimes want to graba blockrect to put into a paper and    */
  101. /* it looks better without the border on paper.                */
  102.  
  103. return r;
  104. }
  105.  
  106.  
  107.